package webSpider.MyScrapy;

import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStream;  
import java.io.InputStreamReader;  
  
import org.apache.http.HttpEntity;  
import org.apache.http.HttpResponse;  
import org.apache.http.client.ClientProtocolException;  
import org.apache.http.client.methods.HttpGet;  
import org.apache.http.util.EntityUtils;  
  
/** 
 * ���ԣ�ȡҳ������ 
 * @author mingyuan 
 * 
 */  
public class WeiBoTest extends RequestCommons {  
  
    /** 
     * ��ӡ�� 
     *  
     * @param in 
     *            InputStream 
     */  
    private void printContent(InputStream in) {  
        BufferedReader reader = null;  
        System.out.println("��ʼ�����������������������������������������������������");
        try {  
            reader = new BufferedReader(new InputStreamReader(in, "utf-8"));  
            String line;  
            while ((line = reader.readLine()) != null) {  
                System.out.println(line);  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            // ���ﲻ�ر�������������  
        }  
    }  
  
    /** 
     * ���ԣ���ȡһ��΢����ַ����ӡ��ҳ������ 
     *  
     * @param finalCookie 
     *            cookie 
     */  
    private void test(String finalCookie) {  
        HttpGet get = new HttpGet("http://weibo.cn/irlucene");  
        setHeader(get);  
        get.setHeader("Cookie", finalCookie.toString());  
        HttpResponse response;  
        try {  
            response = httpclient.execute(get);  
            HttpEntity entity = response.getEntity();  
            printContent(entity.getContent());  
            EntityUtils.consume(entity);  
        } catch (ClientProtocolException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        } finally {  
            get.releaseConnection();  
        }  
    }  
  
    public static void main(String[] args) {  
        Login login = new Login();  
        String userNameValue = "15071115379";  
        String passwordValue = "lwk15071115379";  
        String cookie = login.doLogin(userNameValue, passwordValue);  
        System.out.println("����cookie��" + cookie);  
        new WeiBoTest().test(cookie);  
    }  
  
}  